package handler

import (
	"fmt"
	"lnzw/engine/encrypt"
	"lnzw/server/test/test_fyne/test_3/router"

	"google.golang.org/protobuf/proto"
)

var handlers = map[uint32]func(req proto.Message, rsp proto.Message){}

func register(reqname string, rspname string, f func(req proto.Message, rsp proto.Message)) {
	name := fmt.Sprintf("%s.%s", reqname, rspname)
	h := encrypt.Hash32(name)
	if _, ok := handlers[h]; ok {
		panic("duplicate handler")
	}
	handlers[h] = f
}

func InitHandler() {
	register("ReqCreateMap", "ResCreateMap", ReqCreateMap)
	register("ReqMapInfo", "ResMapInfo", ReqMapInfo)
	register("ReqLogin", "ResLogin", ReqLogin)
	register("ReqMapList", "ResMapList", ReqMapList)
	register("ReqMapUnitInfo", "ResMapUnitInfo", ReqMapUnitInfo)
	router.RegisterAll(handlers)
}
